﻿#include <iostream>
#include "IOCP_Server.h"
#include "ServerLogAdapter.h"
#include "MyServer.h"
using namespace std;

//extern InitializeNetWorlk_Accept();
//#define PR(...) printf(__VA_ARGS__) 

int main()
{
    TRACESVR("测试开始.............");
    //InitializeNetWorlk_Accept();
    //ErrorHandler((LPTSTR)TEXT("CreateThread"));

    //TRACESVR("test func a = %d", 10);

    //printf(GET_FILE_NAME(__FILE__));
    //g_pTrace->PrintMessage("Test Func");
    //PR("a = %d", 10);

    CMyServer* pMyServer = new CMyServer;
    pMyServer->ShowMessage("当前进程ID = %d, 当前线程ID = %d", GetCurrentProcessId(), GetCurrentThreadId());
    int nRet = pMyServer->OnStartServer();
    if (nRet != 0)
    {
        pMyServer->ShowMessage("服务器启动失败!!! nRet = %d", nRet);
        delete pMyServer;
        return 0;
    }

    // 创建事件对象，让ServerShutdown程序能够关闭自己
    HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, L"ShutdownEvent");
    if (hEvent != NULL)
    {
        ::WaitForSingleObject(hEvent, INFINITE);
        TRACESVR("Stop Server ing...");
        ::CloseHandle(hEvent);
    }

    // 关闭服务
    pMyServer->OnStopServer();
    delete pMyServer;
    pMyServer = NULL;

    system("pause");
}
